function editSpec(sId){
	params = {spec: sId};
	url = "calculator";
	loadURL(url, params);
	loadInfoSpecs(sId);
}
function deleteSpec(sId){
	$.post("./specs/php/deleteSpec.php", addSessionVars({specId: sId}),
		function(response, status, xhr){
			if(response.status == "success"){
				loadOwnSpecs();
			}else{
				var msg = "Sorry but there was an error: ";
				alert(msg + xhr.status + " " + xhr.statusText);
			}
		   }, "json");
}


function togglePublishSpecWidget(sId, a){
	var content = $('#own-specs-container').html();
	$('#own-specs-container').html("<div class=\"center loader-gif\"></div>");
	$.post("./specs/php/publishSpec.php", addSessionVars({specId: sId, action: a}),
	function(data){
		if(data.status == "success"){
			loadOwnSpecs();
		}else{
			$('#own-specs-container').html(content);
			var msg = "Sorry but there was an error: ";
			alert(msg + xhr.status + " " + xhr.statusText);
		}
	   }, "json");

}

function getUser(uId){
	window.location = "?"+uId;
}

function loadSpecDetail(sId){

	$('#me_specs tr').each(function(index) {
		if($(this).attr('id') == "tr_"+sId){
			$(this).addClass("spec-detail-list-selected");
		}else{
			$(this).removeClass("spec-detail-list-selected");
		}
	});
	$('#spec-detail-content').fadeOut('fast' , function(){
		$('#spec-detail-content').html("<div class=\"center loader-gif\" style=\"margin-top: 120px;display: inline-block;margin-left: 180px;\"></div>");
		$('#spec-detail-content').fadeIn('fast');
		$("#spec-detail-content").load("specs/spec_detail.php", addPadSessionVars({specId: sId}), function(response, status, xhr) {
			if (status == "error") {
				var msg = "Sorry but there was an error: ";
				$("#spec-detail-content").html(msg + xhr.status + " " + xhr.statusText);
			}else{
			//success
				//$("#spec-detail-content").html(response);
				$("#spec-detail-content").hide();
				$("#spec-detail-content").fadeIn('fast');
			}
		});
	});
}

function loadSpecList(uId){
	$('#spec-list').html("<div class=\"center loader-gif\" style=\"margin-top: 120px;display: inline-block;margin-left: 180px;\"></div>");
	$('#spec-list').load("specs/spec_list.php" , addPadSessionVars({padCICUID: uId}), function(response, status, xhr) {
	  if (status == "error") {
	    var msg = "Sorry but there was an error: ";
	    $('#spec-list').html(msg + xhr.status + " " + xhr.statusText);
	  }else{
		$("#spec-list").hide();
		$("#spec-list").fadeIn('fast');
	  }
	});
}

function loadSpecComments(sId, am){
	$("#spec-comments-out").css({height: $("#spec-comments").height()});
	// fade out inner div
	$("#spec-comments").fadeOut('fast' , function(){
		// change the div content
		$('#spec-comments').html("<div class=\"center loader-gif\" style=\"margin-top: 190px;display: inline-block;margin-left: 373px\"></div>");
		$("#spec-comments").fadeIn('fast');
		
		$("#spec-comments").load("specs/spec_comment.php" ,addPadSessionVars({specId: sId, amount: am}) , function(response, status, xhr) {
		  if (status == "error") {
			var msg = "Sorry but there was an error: ";
			$('#spec-comments').html(msg + xhr.status + " " + xhr.statusText);
		  }else{
			$("#spec-comments-out").animate({height: $("#spec-comments").height()}, function(){
				// show the inner div
				$("#spec-comments").fadeIn('fast');
			});
		  }
		});
	});
}
function deleteComment(cId, sId){
	$.post("specs/php/deleteComment.php", addPadSessionVars({commentId: cId}),
		function(data){
			if(data.status == "success"){
				//$('#tr_'+cId).remove();
				loadSpecComments(sId, 5);
			}else{
				var msg = "Sorry but there was an error: ";
				$("#spec-detail-content").html(msg + xhr.status + " " + xhr.statusText);
			}
		   }, "json");
}

function writeComment(sId, txt){
	var content = $('#spec-comment-write-container').html();
	$('#spec-comment-write-container').html("<div style='margin-top: 18px;' class=\"center loader-gif\"></div>");
	$.post("./specs/php/saveComment.php", addPadSessionVars({specId: sId, comment: txt}),
		function(data){
			if(data.status == "success"){
				loadSpecComments(sId, 5);
			}else{
				$('#spec-comment-write-container').html(content);
			}
		   }, "json");
}

function loadWidgetComments(sId, am){

	$('#widget-more-comments').html("<div class=\"center loader-gif\"></div>");

	$("#widget-more-comments").load("specs/widget_comments.php" ,addPadSessionVars({specId: sId, amount: am}) , function(response, status, xhr) {
	  if (status == "error") {
		var msg = "Sorry but there was an error: ";
		$('#widget-more-comments').html(msg + xhr.status + " " + xhr.statusText);
	  }
	});
}
function loadWidgetRatings(sId, am){

	$('#widget-more-ratings').html("<div class=\"center loader-gif\"></div>");
	
	$("#widget-more-ratings").load("specs/widget_ratings.php" ,addPadSessionVars({specId: sId, amount: am}) , function(response, status, xhr) {
	  if (status == "error") {
		var msg = "Sorry but there was an error: ";
		$('#widget-more-ratings').html(msg + xhr.status + " " + xhr.statusText);
	  }
	});
}


